<?php

namespace App\Admin\Controllers\Agent;

use App\model\agent\AgentCounse;
use App\model\Area;
use App\model\City;
use Encore\Admin\Controllers\AdminController;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Show;

class AgentCounselController extends AdminController
{
    /**
     * Title for current resource.
     *
     * @var string
     */
    protected $title = '咨询列表';

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        $grid = new Grid(new AgentCounse);
        $grid->model()->orderBy('id','desc');
        $grid->column('id', __('Id'));
        $grid->column('name', __('姓名'));
        $grid->column('mobile', __('手机号'));
        $grid->column('sex', __('性别'))->display(function($value){
            return AgentCounse::$SexMap[$value] ?? '男';
        });
        $grid->column('quyu_id', __('区域'))->display(function ($value){
            return City::find($value)->title ?? '';
        });

        $grid->column('area_id', __('面积'))->display(function ($value){
            return Area::find($value)->value ?? '';
        });

        $grid->column('created_at', __('创建时间'));
        $grid->disableActions();


        return $grid;
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     * @return Show
     */
    protected function detail($id)
    {
        $show = new Show(AgentCounse::findOrFail($id));

        $show->field('id', __('Id'));
        $show->field('name', __('Name'));
        $show->field('mobile', __('Mobile'));
        $show->field('quyu_id', __('Quyu id'));
        $show->field('area_id', __('Area id'));
        $show->field('sex', __('Sex'));
        $show->field('created_at', __('Created at'));
        $show->field('updated_at', __('Updated at'));

        return $show;
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        $form = new Form(new AgentCounse);

        $form->text('name', __('Name'));
        $form->mobile('mobile', __('Mobile'));
        $form->number('quyu_id', __('Quyu id'));
        $form->number('area_id', __('Area id'));
        $form->number('sex', __('Sex'));

        return $form;
    }
}
